<#include "copyright.ftl"/>
package ${basePackage}.${moduleName}.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;


import net.common.R;
import net.common.bean.BasePoExample;
import net.common.bean.JqGridRequest;
import ${basePackage}.bean.po.${table.className}Po;

import net.common.controller.BaseRestController;
import net.common.service.IBaseService;
import ${basePackage}.${moduleName}.service.I${table.className}PoService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;

/**
 * <p>controller实现类</p>
 * <p>Table: ${table.tableName} - ${table.remarks}</p>
 * <p></p>
 * @since ${.now}
 */
@RestController
@RequestMapping(value = "/api/${moduleName}/${table.javaProperty}")
@RequiresPermissions("${moduleName}:${table.javaProperty}")
public class ${table.className}PoRestController extends BaseRestController<${table.className}Po> {

	@Resource
	private I${table.className}PoService service;
	
	
	/**
	 * 根据主键查找
	 * @param id
	 * @return
	 */
    @RequestMapping("/select/{id}")
    @RequiresPermissions(":query")
    public R selectByKey(@PathVariable("id")Integer id){
    	${table.className}Po t =  getService().selectByKey(id);
		return R.okResult(t);
    }
	
	@RequestMapping("/save")
	@RequiresPermissions(":save")
    public R save(@Valid @RequestBody ${table.className}Po po){
		logger.debug("新增。。。进入....");
    	int count = getService().insert(po);
		return R.okResult(count);
    }
	
	/**
	 * 
	 * @param key 查询的关键字
	 * @param page 当前页
	 * @param limit 每页显示记录数
	 * @param sidx 排序的字段名称
	 * @return
	 */
	@RequestMapping("/list")
	@RequiresPermissions(":query")
    public R list(JqGridRequest jqRequest){
		PageInfo<${table.className}Po> pageInfo = new PageInfo<>();
		pageInfo.setPageNum(jqRequest.getPageNum());
		pageInfo.setPageSize(jqRequest.getPageSize());
		
		BasePoExample example = jqRequest.createExample();
    	pageInfo = getService().selectByExample(example,pageInfo);
    	
		return R.okResult(pageInfo);
    }
	
    @RequestMapping("/updateByKeySelective")
    @RequiresPermissions(":update")
    public R updateByKeySelective(@Valid @RequestBody ${table.className}Po po){
    	int count =  getService().updateByKeySelective(po);
		return R.okResult(count);
    }
	
    @RequestMapping("/delete")
    @RequiresPermissions(":delete")
    public R delete(@RequestBody List<Long> ids){
    	int count =  getService().deleteByKeyBatch(ids);
		return R.okResult(count);
    }
		
	
	
	
	@Override
	protected IBaseService<${table.className}Po> getService() {
		return this.service;
	}
}
